﻿/*
 * Created by SharpDevelop.
 * User: yizhanga
 * Date: 2015/11/5
 * Time: 15:14
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;
using System.Collections.Generic; 
using System.IO;
using Fiddler;

using Newtonsoft.Json;
using Hotel.Product.SearchService.Entity;
using CServiceStack.ProtoBuf;

namespace CtripProtobufWithInspector
{
	/// <summary>
	/// Description of UserControl1.
	/// </summary>
	public partial class ResponseControl : UserControl
	{
		MemoryStream responseStream;
		
		public ResponseControl()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		public RichTextBox getRichTextBox()
		{
			return this.richTextBox;
		}
		
		public void ResponseTextDisplay(byte[] str)
        {
			responseStream = new MemoryStream(str);

            if (null != str && str.Length > 0)
            {
            	FiddlerApplication.Log.LogString(responseStream.ToString());
            	SearchHotelDataResponse data = Serializer.Deserialize<SearchHotelDataResponse>(responseStream);
            	this.richTextBox.Text = JsonConvert.SerializeObject(data);
            }
            else
                this.richTextBox.Text = "";
        }
		
		public void RequestTextDisplay(byte[] str)
        {
			responseStream = new MemoryStream(str);
			
            if (null != str && str.Length > 0)
            {
				CServiceStack.ProtoBuf.Meta.RuntimeTypeModel.Default[typeof(Hotel.Product.SearchService.Entity.SearchSortType)].EnumPassthru = true;
            	CServiceStack.ProtoBuf.Meta.RuntimeTypeModel.Default[typeof(Hotel.Product.SearchService.Entity.PlotingType)].EnumPassthru = true;
				
				responseStream.Position = 0;
            	
            	SearchHotelDataRequest data = Serializer.Deserialize<SearchHotelDataRequest>(responseStream);
				this.richTextBox.Text = JsonConvert.SerializeObject(data);
            	
            }
            else
                this.richTextBox.Text = "";
        }
	}
}
